/*----------------------绑定手势---------------------*/

  //位置移动
  mc.on("panstart",function(e){
	  mapScale = parseFloat($$('.map-container').data('scale'));
	  //获取现在的坐标
	  mapTop = parseFloat($$('.map-container').data('axisY'));
      mapLeft = parseFloat($$('.map-container').data('axisX'));
      //console.log('start');
  });
  mc.on("panmove",function(e){
	  //获取位移
	  var dx = parseFloat(e.deltaX);
	  var dy = parseFloat(e.deltaY);
	  mapdx = dx;
	  mapdy = dy;
	  var cmapleft = mapLeft+dx;
	  var cmaptop  = mapTop+dy;
	  //移动
	  $$('.map-container').transform('translate('+cmapleft+'px,'+cmaptop+'px) scale('+mapScale+')');
	  //console.log(e);
  });
  mc.on("panend",function(){
	  mapTop  += mapdy;
	  mapLeft += mapdx;
	  $$('.map-container').data('axisY',mapTop);
	  $$('.map-container').data('axisX',mapLeft);
  });
  
  //地图缩放
  mc.on("pinchstart",function(e){
	  mapTop = parseFloat($$('.map-container').data('axisY'));
      mapLeft = parseFloat($$('.map-container').data('axisX'));
	  //获取现在比例
	  mapScale = parseFloat($$('.map-container').data('scale'));
  });
  mc.on("pinchmove",function(e){
	  //获取比例
      var dscale = e.scale;
      mapdscale = dscale
      var cmapscale = mapScale*dscale;
	  //缩放
	  $$('.map-container').transform('translate('+mapLeft+'px,'+mapTop+'px) scale('+cmapscale+')');

  });
  mc.on("pinchend",function(){
	  mapScale *= mapdscale;
	  $$('.map-container').data('scale',mapScale);
  });

//全局事件
$$(document).on('click','.walkable.path-block',function(){
	//更改选中状态
	$$('.path-block.active').removeClass('active');
	$$(this).addClass('active');
	//marker
	var makerpos = getMarkerPos();
	$$('.loc-icon').css({top:makerpos.y+'px',left:makerpos.x+'px'});
	$$('.loc-icon').show();
	//信息框
	$$('#findPath .toolbar').show();
	//信息框文本
	var realX = (makerpos.x + markerSize/2)* mapRatioW;
	var realY = (makerpos.y + markerSize) * mapRatioH;
	var name = '('+realX.toFixed(2).toString()+','+realY.toFixed(2).toString()+')';
	$$('#findPath .toolbar .loc-name').html(name);
});
$$(document).on('click','.startloc',function(){
	var axisX = parseInt($$('.path-block.active').data('axisX'));
	var axisY = parseInt($$('.path-block.active').data('axisY'));
	startblock = [axisX,axisY];
	//清空画布
	$$('#floor-canvas').attr('height',mapH);
	//清空信息框和marker
	$$('#findPath .toolbar').hide();
	$$('.loc-icon-start').hide();
	$$('.loc-icon-end').hide();
	$$('.loc-icon').hide();
    //添加新marker
	var makerpos = getMarkerPos();
	$$('.loc-icon-start').css({top:makerpos.y+'px',left:makerpos.x+'px'});
	$$('.loc-icon-start').show();
});
$$(document).on('click','.endloc',function(){
	//起点必须存在
	if(startblock){
		var axisX = parseInt($$('.path-block.active').data('axisX'));
    	var axisY = parseInt($$('.path-block.active').data('axisY'));
    	endblock = [axisX,axisY];
    	//清空信息框和marker
    	$$('#findPath .toolbar').hide();
    	$$('.loc-icon-end').hide();
    	$$('.loc-icon').hide();
    	//添加新marker
    	var makerpos = getMarkerPos();
    	$$('.loc-icon-end').css({top:makerpos.y+'px',left:makerpos.x+'px'});
    	$$('.loc-icon-end').show();
    	//寻找路径
  	  	findPath();
    	//绘制路径
  	  	drawRoute();
	}else{
		myApp.alert('请先选择起点');
	}
});
$$(document).on('click','.walk-icon',function(){
	//选择定位点为起点
	if(currentblock[0]){
		startblock = [currentblock[0],currentblock[1]];
	}else{
		myApp.alert("无法获取您现在的位置");
		return;
	}
	
	//选择当前点为终点
	var axisX = parseInt($$('.path-block.active').data('axisX'));
	var axisY = parseInt($$('.path-block.active').data('axisY'));
	endblock = [axisX,axisY];
	//清空信息框和marker
	$$('#findPath .toolbar').hide();
	$$('.loc-icon-start').hide();
	$$('.loc-icon-end').hide();
	$$('.loc-icon').hide();
	//添加新marker
	var makerpos = getMarkerPos();
	$$('.loc-icon-end').css({top:makerpos.y+'px',left:makerpos.x+'px'});
	$$('.loc-icon-end').show();
	//寻找路径
  	findPath();
	//绘制路径
  	drawRoute();
});